%上界
clear
clc
NUM_timesamples = 1000;
tilde_h = (randn(NUM_timesamples) + j*randn(NUM_timesamples)) / sqrt(2);
Pathloss = 1;
h = sqrt(Pathloss) * tilde_h;
SNR_dB = -10:5:30;

for I_SNR = 1: length(SNR_dB)
    rho = 10^(SNR_dB(I_SNR)/10);

    for t = 1:NUM_timesamples
    h_temp(t) = h(t)*h(t)';
    end
    h_average= sum(h_temp)/NUM_timesamples;

    Capacity(I_SNR)=log2(abs(1+rho*h_average));
end

figure(1)
hold on
plot(SNR_dB, Capacity, 'ro-')
legend('Ergodic Capacity', 'Location', 'NorthWest')
xlabel('\rho (in dB)')
ylabel('Ergodic Capacity (bps/Hz)')
grid